setInterval(function(){ save();}, 3000);

window.onload = function(){
	chrome.storage.sync.get({zengylNoteExtContent: ""}, function(content) {
		document.getElementById("text").value = content.zengylNoteExtContent;
	});
};

document.addEventListener('keydown', function(e){
    if (e.keyCode == 83 && e.ctrlKey){
        e.preventDefault();
        save();
     }
});

document.getElementById("text").oninput = function(){
    saveState(false);
};

function save(){
	if(document.getElementById("text") != null){
		var storage = {zengylNoteExtContent: ""};
		storage.zengylNoteExtContent = document.getElementById("text").value;
		chrome.storage.sync.set(storage, function(){});
		saveState(true);
	}
}

function saveState(s){
	document.getElementById("state").innerHTML = s?"Saved!":"Unsaved!";
	document.getElementById("state").style.color = s?"#009900":"#990000";
}
